import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

import Procurement from "@/views/procurement";
import DynamicList from "@/views/procurement/dynamic/dynamicList";
import DynamicDetails from "@/views/procurement/dynamic/dynamicDetails";
import NoticeList from "@/views/procurement/notice/noticeList";
import NoticeDetails from "@/views/procurement/notice/noticeDetails";
import PolicyList from "@/views/procurement/policy/policyList";
import PolicyDetails from "@/views/procurement/policy/policyDetails";
import ComplaintList from "@/views/procurement/complaint/complaintList";
import ComplaintDetails from "@/views/procurement/complaint/complaintDetails";
import User from "@/views/procurement/user";
import UserInformation from "@/views/procurement/user/userInformation";
import EnterpriseInformation from "@/views/procurement/user/enterpriseInformation";
import BidList from "@/views/procurement/user/bidList";
import TargetList from "@/views/procurement/user/targetList";
import TargetSubmit from "@/views/procurement/user/targetSubmit";

/* Router Modules */
export const constantRoutes = [
  {
    path: "/login",
    component: () => import("@/views/login/index"),
    hidden: true,
  },
  {
    path: "/",
    component: () => import("@/layout/procurement"),
    name: "procurement",
    redirect: "index",
    children: [
      // 首页
      {
        path: "/index",
        name: "index",
        component: Procurement,
      },
      // 平台动态列表
      {
        path: "/dynamicList",
        name: "dynamicList",
        component: DynamicList,
      },
      // 平台动态详情
      {
        path: "/dynamicDetails",
        name: "dynamicDetails",
        component: DynamicDetails,
      },
      // 信息公共列表
      {
        path: "/noticeList",
        name: "noticeList",
        component: NoticeList,
      },
      // 信息公共详情
      {
        path: "/noticeDetails",
        name: "noticeDetails",
        component: NoticeDetails,
      },
      // 政策法规列表
      {
        path: "/policyList",
        name: "policyList",
        component: PolicyList,
      },
      // 政策法规详情
      {
        path: "/policyDetails",
        name: "policyDetails",
        component: PolicyDetails,
      },
      // 违规投诉列表
      {
        path: "/complaintList",
        name: "complaintList",
        component: ComplaintList,
      },
      // 违规投诉详情
      {
        path: "/complaintDetails",
        name: "complaintDetails",
        component: ComplaintDetails,
      },
      // 用户中心
      {
        path: "/user",
        name: "user",
        component: User,
        children: [
          // 用户中心
          {
            path: "/userInformation",
            name: "userInformation",
            component: UserInformation,
          },
          // 企业信息
          {
            path: "/enterpriseInformation",
            name: "enterpriseInformation",
            component: EnterpriseInformation,
          },
          // 企业信息
          {
            path: "/bidList",
            name: "bidList",
            component: BidList,
          },
          // 我的投标
          {
            path: "/targetList",
            name: "targetList",
            component: TargetList,
          },
          // 标资料提交
          {
            path: "/targetSubmit",
            name: "targetSubmit",
            component: TargetSubmit,
          },
        ],
      },
      // 标资料提交
      {
        path: "/targetSubmit",
        name: "targetSubmit",
        component: TargetSubmit,
      },
    ],
  },
  {
    path: "/applylicense",
    component: (resolve) => require(["@/views/applylicense"], resolve),
    hidden: true,
  },
];

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [{ path: "*", redirect: "/404", hidden: true }];

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes,
  });

const router = createRouter();

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;
